package com.js.controller;


import com.js.entity.DClass;
import com.js.service.DClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (DClass)表控制层
 *
 * @author makejava
 * @since 2022-06-06 22:55:59
 */
@RestController
@RequestMapping("dClass")
@CrossOrigin
@Slf4j
public class DClassController {
    /**
     * 服务对象
     */
    @Resource
    private DClassService dClassService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<DClass> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.dClassService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param dClass 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<DClass> add(@RequestBody DClass dClass) {
        return ResponseEntity.ok(this.dClassService.insert(dClass));
    }

    /**
     * 编辑数据
     *
     * @param dClass 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    public void update( @RequestBody DClass dClass){
        dClassService.update(dClass);
    }
    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.dClassService.deleteById(id));
    }
    @GetMapping("/query")
    public List<DClass> queryAll(){
        Date date = new Date();
        log.info("对dClass的操作<===>查询全部<===>此时时间为{}",date);
        List<DClass> dClasses = dClassService.queryAll();
        return dClasses;
    }

}

